package com.example.a30;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class StatisticsActivity extends AppCompatActivity {

    private DBHelper dbHelper;
    private TextView totalDailyExpenseTextView;
    private TextView totalEntertainmentExpenseTextView;
    private TextView totalOtherExpenseTextView;
    private TextView totalCommonExpenseTextView;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_statistics);

        dbHelper = new DBHelper(this);
        totalDailyExpenseTextView = findViewById(R.id.totalDailyExpenseTextView);
        totalEntertainmentExpenseTextView = findViewById(R.id.totalEntertainmentExpenseTextView);
        totalOtherExpenseTextView = findViewById(R.id.totalOtherExpenseTextView);
        totalCommonExpenseTextView = findViewById(R.id.totalCommonExpenseTextView);

        updateTotalExpenses();
    }

    private void updateTotalExpenses() {
        double totalDailyExpense = dbHelper.getTotalDailyExpense();
        double totalEntertainmentExpense = dbHelper.getTotalEntertainmentExpense();
        double totalOtherExpense = dbHelper.getTotalOtherExpense();
        double totalCommonExpense = totalDailyExpense + totalEntertainmentExpense + totalOtherExpense;

        totalDailyExpenseTextView.setText("Total Daily Expense: " + totalDailyExpense);
        totalEntertainmentExpenseTextView.setText("Total Entertainment Expense: " + totalEntertainmentExpense);
        totalOtherExpenseTextView.setText("Total Other Expense: " + totalOtherExpense);
        totalCommonExpenseTextView.setText("Common Total Expense: " + totalCommonExpense);
    }
}

